package com.four.shop.controller;

import com.four.shop.entity.Observer;
import com.four.shop.service.ObserverService;
import com.four.shop.vo.ObserverVo;
import com.guli.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @Author:wsy
 * @Date: 2021/12/9/15:35
 */
@RestController
@RequestMapping("shop/observer")
public class ObserverController {

    @Autowired
    private ObserverService observerService;


    /**
     * 商品评论列表
     *
     * @param vo
     */
    @PostMapping("/list")
    public R list(@RequestBody ObserverVo vo){

        List<Observer> observerList = observerService.list(vo);
        return R.ok().put("page",observerList);
    }

    /**
     * id逻辑删除
     *
     * @param id
     */
    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable Long id){

        try {
            observerService.deleteById(id);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 添加虚拟评论
     *
     * @param
     */
    @PostMapping("/add")
    public void add(@RequestBody Observer observer){

        observerService.add(observer);
    }

    /**
     *
     * 回显数据
     *
     * @param id
     */
    @GetMapping("/findById/{id}")
    public Observer findById(@PathVariable("id") Long id){

        return observerService.findById(id);
    }

    /**
     * 回复评论
     *
     * @param id
     * @param observerVo
     */
    @PutMapping("/addCriContentById/{id}")
    public void addCriContentById(@PathVariable("id") Long id,
                                @RequestBody ObserverVo observerVo){
        observerService.addCriContentById(id,observerVo.getCriContent());
    }
}
